<?php
	require_once ("../../config.inc.php");
	require_once ("../../include/mysql.inc.php");
	require_once ("../../include/article.inc.php");
	
	$articleDao = new Article();
	$pageIndex = mysql_escape_string($_POST["pageIndex"]);
	$typeId = mysql_escape_string($_POST["typeId"]);
	if (empty($typeId)) {
		$typeId = '';
	}
	
	$articleList = $articleDao->query($typeId, $pageIndex, ARTICLE_PAGE_SIZE);
	$articleNum = $articleDao->count($typeId);

	$dom = new DOMDocument("1.0","UTF-8");
	$articles = $dom->createElement("articles");
	$articles->setAttribute("total", $articleNum);
	$articles->setAttribute("size", ARTICLE_PAGE_SIZE);
	$articles->setAttribute("index", $pageIndex);
	foreach ($articleList as $row) {
		$article = $dom->createElement("article");
		$article->setAttribute("id",$row[id]);
	
		$title = $dom->createElement("title", $row[title]);
		$content = $dom->createElement("content", $row[content]);
		$time = $dom->createElement("time", $row[time]);
		$adminId = $dom->createElement("adminId", $row[adminId]);
		$top = $dom->createElement("top", $row[top]);
		$typeId = $dom->createElement("typeId", $row[typeId]);
		$typeName = $dom->createElement("typeName", $row[name]);
	
		$article->appendChild($title);
		$article->appendChild($content);
		$article->appendChild($time);
		$article->appendChild($adminId);
		$article->appendChild($top);
		$article->appendChild($typeId);
		$article->appendChild($typeName);
	
		$articles->appendChild($article);
	}
	
	$dom->appendChild($articles);
	header("Content-type:text/xml");
	$xmlfile = $dom->saveXML();
	file_put_contents("../../xml_data/articles.xml",$xmlfile);
	echo $xmlfile;
	
?>